package com.ruoyi.fina.controller;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fina.domain.FinSummary;
import com.ruoyi.fina.service.IFinSummaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务汇总Controller
 * 
 * @author useragent-1
 * @date 2025-05-26
 */
@Controller
@RequestMapping("/fina/summary")
public class FinSummaryController extends BaseController
{
    private String prefix = "fina/summary";

    @Autowired
    private IFinSummaryService finSummaryService;

    @RequiresPermissions("fina:summary:view")
    @GetMapping()
    public String summary()
    {
        return prefix + "/summary";
    }

    /**
     * 查询财务汇总列表
     */
    @RequiresPermissions("fina:summary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FinSummary finSummary)
    {
        startPage();
        List<FinSummary> list = finSummaryService.selectFinSummaryList(finSummary);
        return getDataTable(list);
    }

    /**
     * 导出财务汇总列表
     */
    @RequiresPermissions("fina:summary:export")
    @Log(title = "财务汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FinSummary finSummary)
    {
        List<FinSummary> list = finSummaryService.selectFinSummaryList(finSummary);
        ExcelUtil<FinSummary> util = new ExcelUtil<FinSummary>(FinSummary.class);
        return util.exportExcel(list, "财务汇总数据");
    }

    /**
     * 新增财务汇总
     */
    @RequiresPermissions("fina:summary:add")
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("userString", ShiroUtils.getSysUser().toUserString());
        return prefix + "/add";
    }

    /**
     * 新增保存财务汇总
     */
    @RequiresPermissions("fina:summary:add")
    @Log(title = "财务汇总", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FinSummary finSummary)
    {
        finSummary.setSummaryId(ShiroUtils.getUserId());
        return toAjax(finSummaryService.insertFinSummary(finSummary));
    }

    /**
     * 修改财务汇总
     */
    @RequiresPermissions("fina:summary:edit")
    @GetMapping("/edit/{summaryId}")
    public String edit(@PathVariable("summaryId") Long summaryId, ModelMap mmap)
    {
        FinSummary finSummary = finSummaryService.selectFinSummaryBySummaryId(summaryId);
        finSummary.setUserId(ShiroUtils.getUserId());
        mmap.put("finSummary", finSummary);
        mmap.put("userString",ShiroUtils.getSysUser().toUserString());
        return prefix + "/edit";
    }

    /**
     * 修改保存财务汇总
     */
    @RequiresPermissions("fina:summary:edit")
    @Log(title = "财务汇总", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FinSummary finSummary)
    {
        return toAjax(finSummaryService.updateFinSummary(finSummary));
    }

    /**
     * 删除财务汇总
     */
    @RequiresPermissions("fina:summary:remove")
    @Log(title = "财务汇总", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(finSummaryService.deleteFinSummaryBySummaryIds(ids));
    }
}
